package com.moshang.mall.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author moshang
 * @Package : com.moshang.mall.cart.vo
 * @date 2020-09-18
 * @Description : 购物车
 **/
public class Cart {
    private List<CartItem> cartItems;
    private Integer countNum;//商品数量
    private Integer countType;//商品类型数量
    private BigDecimal totalAmount;  //商品总价
    private BigDecimal reduce=new BigDecimal("0.00"); //减免价格

    public List<CartItem> getCartItems() {
        return cartItems;
    }

    public void setCartItems(List<CartItem> cartItems) {
        this.cartItems = cartItems;
    }

    public Integer getCountNum() {
      int count=0;
        if (cartItems!=null&&cartItems.size()>0){
            for (CartItem item:cartItems) {
                count+=item.getCount();
            }
        }
        return count;
    }


    public Integer getCountType() {
        int count=0;
        if (cartItems!=null&&cartItems.size()>0){
            for (CartItem item:cartItems) {
                count+=1;
            }
        }
        return count;
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount=new BigDecimal("0");
        if (cartItems!=null&&cartItems.size()>0){
            for (CartItem item:cartItems) {
               amount=amount.add(item.getTotalPrice());
            }
        }
        BigDecimal subtract = amount.subtract(getReduce());
        return subtract;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
